package com.serilizable.demo;


import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import com.serilizable.demo.Account;

import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AccountTest {

	
	
	@Test
	public void AccountTest0() {
		
		try {
			Account a1 = new Account("miiii3", "hahah", 1000);
			ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("c:/dev/account.txt"));
			os.writeObject(a1);
			
			os.flush();
			os.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		try{
			ObjectInputStream is = new ObjectInputStream(new FileInputStream("c:/dev/account.txt"));
			Account a2 = (Account)is.readObject();
			is.close();
			
		} catch (Exception e){
			e.printStackTrace();
		}
		
	}
	
	//@Test
	public void AccountTest2() {


		try {
			Account a1 = new Account("miiii3", "hahah", 1000);
			System.out.println("read before Serializable: ");
			System.out.println("name: " + a1.name);
			System.out.println("pswd: " + a1.pswd);
			System.out.println("money: " + a1.money);
			
			ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("c:/dev/account.txt"));
			os.writeObject(a1);
			
			os.flush();
			os.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		

	}
	
	//@Test
	public void AccountTest1() {


		try{
			ObjectInputStream is = new ObjectInputStream(new FileInputStream("c:/dev/account.txt"));
			Account a2 = (Account)is.readObject();
			
			is.close();
			
			System.out.println("read after Serializable: ");
			System.out.println("name: " + a2.name);
			System.out.println("pswd: " + a2.pswd);
			System.out.println("money: " + a2.money);
			
		} catch (Exception e){
			e.printStackTrace();
		}
		

	}

}
